
<template>
    <v-md-editor v-model="editorValue"
                 :disabled-menus="[]"
                 @upload-image="handleUploadImage"
                 width="100%"
                 height="400px"></v-md-editor>
</template>

<script>
import { loadCss, loadScript } from '@/utils/loadscript'
import axios from 'axios'
export default {
  name: 'mdEditor',
  data() {
    return {
      editorValue: this.$props.content != null ? this.$props.content : "",
    }
  },
  components: {
  },
  props: {
    // 接收值父组件传递值
    content: String
  },
  async created() {
    console.log("--------加载md编辑器")
  },
  async mounted() {

  },

  methods: {
    // v-md-editor 文件上传
    handleUploadImage(event, insertImage, files) {
    console.log("=>(index.vue:36) files", files);
      // console.log(files);
      // 上传
      for (let i = 0; i < files.length; i++) {
      var newForm =new FormData();
        newForm.append('file',files[i])
        axios.post(`/api/api/oss/upload`,newForm).then(res=>res.data).then(res=>{

          // 获取返回数据
          // 添加图片到内容
          insertImage({
            url: `http://codeapi.liumingtai.com/api/oss/getimage/${res?.fileName}`,
            desc: res?.fileName
          });
        })

      }
    },
  },
  watch: {
    editorValue: function (newNum, oldNum) {
      // 修改调用者传入的值
      this.$emit('update:content', newNum)
    }
  },
}
</script>

<style>
</style>

